<div class="modal-header" style="border-bottom: 0">
  <button type="button" class="close" data-dismiss="modal" aria-label="关闭" ><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body no-padding-top">
	<div class="box-tabs">
		<div class="tabable">
			<ul class="nav nav-tabs tabs-flat nav-justified">
				<li id="leave" style="width: 300px">
					<a data-toggle="tab" href="#tab-salescustomer"  onclick="handlerToggle('请假');"> 填写请假信息 </a>
				</li>
				<li id="absent" style="width: 300px">
					<a data-toggle="tab" href="#tab-salescustomer"  onclick="handlerToggle('缺席');"> 学员缺勤 </a>
				</li>
			</ul>
			<div class="tab-content tabs-flat">
	   		<div class="tab-pane active" id="tab-content">
	      	<form class="form-horizontal form-editor form-editor-leave">
						<div class="row" id="info">
							<div class="col-sm-4">
								<div class="form-group">
									<label class="col-sm-4 control-label" for="leaveDate">请假时间</label>
									<div class="col-sm-8">
										<div class="input-group date date-selector">
											<input name="leaveDate" id="leaveDate" type="text" class="form-control" readonly="readonly" /> 
											<span class="input-group-addon"> <span class="fa fa-calendar"></span> </span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-sm-4">
								<div class="form-group">
									<label class="col-sm-4 control-label" for="length">请假天数</label>
									<div class="col-sm-8">
										<div class="input-group">
											<input type="text" name="length" id="length" class="form-control" value="1" readonly="readonly" /> 
											<span class="input-group-addon">天</span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-sm-4" hidden="hidden">
								<div class="form-group">
									<label class="col-sm-4 control-label" for="parentId">家长</label>
									<div class="col-sm-8">
										<select name="parentId" id="parentId" class="chosen-select" data-entity="com.app.miwawa.api.esm.entity.customer.Parents"></select> 
										<input name="student" 		id="student" 		type="hidden"/> 
										<input name="studentId" 	id="studentId" 	type="hidden"/> 
										<input name="classes" 		id="classes" 		type="hidden"/> 
										<input name="classesId" 	id="classesId" 	type="hidden"/> 
										<input name="contractId" 	id="contractId" type="hidden"/> 
										<input name="actor" 			id="actor" 			type="hidden"/> 
										<input name="actorId" 		id="actorId" 		type="hidden"/>
									</div>
								</div>
							</div>
						</div>
						<div class="row" >
							<div class="col-sm-8">
								<div class="form-group">
									<label class="col-sm-2 control-label" for="reason">请假原因</label>
									<div class="col-sm-10">
										<select name="reason" id="reason" class="chosen-select" data-url="/miwawa/default/common/select.json" data-pcode="c_leave_type" data-entity="com.app.miwawa.api.system.entity.config.Codec">
										</select>
									</div>
								</div>
							</div>
						</div>
					</form>
				
					<form class="form-horizontal form-editor form-absent">
						<div class="row" id="info">
							<div class="col-sm-12">
								<div class="form-group">
									<div class="col-sm-12">
										<div class="callout callout-warning">
											<h5>注1：缺勤处理将会扣除课时！！！</h5>
											<h5>注2：该学员请假次数已用完，如果确定将按缺勤处理！！！</h5>
											<h5>注3：可以在班级管理中查看学员剩余请假次数，并可以修改该学员的最大请假次数。</h5>
										</div>
									</div>
								</div>
							</div>
						</div>
					</form>
	   		</div>
	 		</div>
		</div>
	</div>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	<button type="button" class="btn btn-primary" id="submit" onclick="handlerSubmit(this, '#editor-form-leave', '.form-editor-leave', 'beforeLeave');" data-not-hide="true" data-submit-callback="afterLeave">确认</button>
	<button type="button" class="btn btn-primary" id="sure" onclick="handlerSure();">确定</button>
</div>

<script type="text/javascript">
<!--
require(['domReady'],function(domReady){
	domReady(function () {
		require(['moment','jquery.plugin.form'],function(moment, form){
			form.tooltip("[data-toggle='tooltip']");
			$moment = moment;
			if(selectrows[0].toplimit != ""){
				if(selectrows[0].toplimit >= 0 && selectrows[0].toprested == 0){
					handlerToggle("缺席");
					jQuery("#absent").addClass("active");
					jQuery("#leave").hide();
				}else{
					handlerToggle("请假");
					jQuery("#leave").addClass("active");
					if(!$moment().isAfter(leavedate)){
						jQuery("#absent").hide();
					}
				}
			}else{
				handlerToggle("请假");
				jQuery("#leave").addClass("active");
				if(!$moment().isAfter(leavedate)){
					jQuery("#absent").hide();
				}
			}
		});
	});
});

	function handlerToggle(status){
		switch (status){
			case "请假":jQuery(".form-editor-leave").show();
									jQuery(".form-absent").hide();
									jQuery("#submit").show();
									jQuery("#sure").hide();
									return;
			case "缺席":jQuery(".form-editor-leave").hide();
									jQuery(".form-absent").show();
									jQuery("#sure").show();
									jQuery("#submit").hide();
									return;
		}
	}

	// 确认请假前回调
	function beforeLeave(form){
		var parent = jQuery("#parentId > option:selected",form).text();
		jQuery("#parent").val(parent);
		return true;
	}
	
	// 保存请假后的回调
	function afterLeave(){
		jQuery("#extension-modal").modal("hide");
	}
	
	function handLeave(){
		var params = {
				"entityClass":"com.app.miwawa.api.eam.entity.StudentLeave",
				"beans":[]
		};
		params.beans.push({
			"length":'1',
			"reason":jQuery("#reason").val(),
			"LeaveDate": leavedate.format("YYYY-MM-DD"),
			"student":selectrows[0].student,
			"studentId":selectrows[0].studentId,
			"classes":classes.name,
			"classesId":classes.id,
			'contractId': selectrows[0].contractId,
			"actor":"老师:"+username,
			"actorId":userid,
			"status":"0",
			"invalid":"F"
		});
		jQuery.ajaxsend({
			url:"/miwawa/{dbname}/student/leave/save".replace("{dbname}",dbname),
			data:params,
			success:function(data){
				afterLeave();
				jQuery("[data-toggle='tooltip']","#table-history").tooltip("destroy");
			}
		});
}
	
	function handlerSure(){
		jQuery.message.confirm("缺勤处理也会扣除课时，您确定要对此学员进行缺勤处理吗？",function(confirm){
			if(confirm){
				var params = {
						"entityClass":"com.app.miwawa.api.eam.entity.StudentCheck",
						"beans":[]
				};
				params.beans.push({
					"checkDate": leavedate.format("YYYY-MM-DD"),
					"checkTime": $moment().format("HH:mm"),
					"student":selectrows[0].student,
					"studentId":selectrows[0].studentId,
					"classes":classes.name,
					"classesId":classes.id,
					"actor":"老师:"+username,
					"actorId":userid,
					'contractId': selectrows[0].contractId,
					'item':selectrows[0].item,
					"status":"1",
					"invalid":"F"
				});
				jQuery.ajaxsend({
					url:"/miwawa/{dbname}/student/check/all".replace("{dbname}",dbname),
					data:params,
					success:function(data){
						afterLeave();
						jQuery("[data-toggle='tooltip']","#table-history").tooltip("destroy");
					}
				});
			}
		});
	}
//-->
</script>